const dropMenu = {
	props: ['dropitem'],
	template: '<select id="docType" class="droptitle" style="text-align: center; text-align-last: center;"><option v-for="item in dropitem" :value="item.id" style="text-align: center; text-align-last: center;">{{item.name}}</option></select>'
};

var vueApp = new Vue({
	el: '.aui-scrollView',
	data: {
		majors: null
	},
	components: {
		dropmenu: dropMenu
	},
	created: function() {
		this.initDrop();
	},
	methods: {
		initDrop: function() {
			var that = this;
			var typeId = this.urlid();
			if(typeId == -1) {
				history.back(-1);
				return;
			}
			util.get("https://www.maksdu.com/app/category/get",{
				categoryid: typeId
			},function(result){
				if(result.value) {
					that.majors = result.value;
				}
			})
		},
		urlid: function() {
			var url = window.location.search;
			if(url.length>1) {
				url = url.substring(1);
				var params = url.split("=");
				docid = params[1];
				if(docid) {
					return docid;
				} else
					return -1;
			} 
		},
		submit: function() {
			var typeid = $("#docType").val();
			var title = $("#texttitle").html();
			var content = $("#document").html();
			var token = window.localStorage.getItem('token');
			util.tokenPost("https://www.maksdu.com/app/post/submit",
				{
					title: title,
					context: content,
					typeid: typeid,
				},
				function(result) {
					if(!result.login_status) {
						var urls = window.location.url;
						window.location.replace("../../login/?redirect="+urls);
					} 
					else
						history.back(-1);
				}
			);
			$(".textarea").html("")
		}
	}
});